package cat.music.ut.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import cat.music.ut.base.BaseRvAdapter
import cat.music.ut.base.CommonRvHolder
import cat.music.ut.bean.AudioInfo
import cat.music.ut.component.click
import cat.music.ut.databinding.ItemQualityBinding
import cat.music.ut.databinding.ItemRecordBinding
import com.arialyy.aria.core.download.DownloadEntity

class DownloadRecordAdapter(context: Context, data: MutableList<DownloadEntity>) :
    BaseRvAdapter<DownloadEntity, ItemRecordBinding>(context, data) {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): CommonRvHolder<ItemRecordBinding> {
        return CommonRvHolder(
            ItemRecordBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(
        holder: CommonRvHolder<ItemRecordBinding>,
        position: Int,
        vb: ItemRecordBinding,
        bean: DownloadEntity
    ) {
        vb.ivTitle.text = getName(bean)
        holder.itemView.click {
            listener?.clickItem(bean)
        }
    }
    private fun getName(data:DownloadEntity): String {
        return data.fileName.split(".")[0]
    }
    var listener: Listener? = null

    interface Listener {
        fun clickItem(data: DownloadEntity)
    }
}